
var app = getApp();
var config = require('../../../../config.js');
var app = getApp();
var mInterval;
var timeFun;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    animationData: {},
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var fromType = options.fromType;
    if (fromType == 1) {
      wx.setNavigationBarTitle({
        title: '学法达人冲榜赛'
      })
    }else{
      this.setData({
        times:options.times,
        isShare:options.isShare,
      })
     
      wx.setNavigationBarTitle({
        title: '学法达人闯关赛'
      })
    }
    this.setData({
      fromType: fromType
    });
    this.startAnim();
    this.checkTheInternet();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {


  },
  onShow: function () {
   
  },

  checkTheInternet : function(){
    var that = this;
    if (wx.openBluetoothAdapter) {
      wx.getNetworkType({
        success: function (res) {
          // 返回网络类型, 有效值：
          // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
          var networkType = res.networkType
          if (networkType != "none") {
            console.log(networkType);
            timeFun = setTimeout(function () {
              clearInterval(mInterval);
             that.openAnsQuesPage();

            }, 3000);
          } else {
            wx.showToast({
              title: '请检查网络连接',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })

    } else {
      // 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }


  },

  /**
   * 打开每日精彩page
   */
  openAnsQuesPage: function(){
    var that=this;
    var fromType = this.data.fromType;
    if (fromType == 1){
      //每日精彩
      wx.redirectTo({
       url: '../../games/answer/answerQuestions'
      })
    }else{
     //通关
      //每日精彩
      wx.redirectTo({
        url: '../../games/throughGame/throughGame?isShare='+that.data.isShare+'&times='+that.data.times
        
      })
    }
   
  },


  startAnim: function(){
    var animation = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: 'linear'
    })
    var that = this;
    this.animation = animation
    that.rotateAndScale();
    var animation_interval = 1000;
    var n = 20;
    var step = 1;
    var animationFun = function () {
      if (step <= n) {
      }
      that.rotateAndScale();
      console.log("step===" + step);
      step++;
      //  else {
      //   clearInterval(mInterval);
      // }
    }
    mInterval = setInterval(animationFun, animation_interval);
  },


  rotateAndScale: function () {
    // 旋转同时放大
    this.animation.opacity(0.2).scale(8, 8).step(
      {
        delay: 100,
        duration: 2000,
        timingFunction: 'ease-in-out'
      }
    ).scale(1).opacity(0.8).step({
      delay: 200,
      duration: 2000,
      timingFunction: 'step-start'
    })
    this.setData({
      animationData: this.animation.export()
    })
  },


  /**
    * 生命周期函数--监听页面卸载
    */
  onUnload: function () {
    console.log("onUnload执行了");
    //当页面卸载时 停止定时任务
    clearTimeout(timeFun);
    clearInterval(mInterval);
  },
  onHide: function(){
    console.log("onHide");

  }

})


